var t = getApp();

Component({
    properties: {
        page_data: {
            type: Array,
            value: [],
            observer: function(t) {
                if (t && t.length >= 1) {
                    var a = this.data.listData.concat(t);
                    this.setData({
                        listData: a
                    });
                }
            }
        }
    },
    pageLifetimes: {
        show: function() {
            this.setData({
                index: 0,
                password_show: !1,
                show_pay: !1,
                show_dialog: !1,
                pay_index: 0,
                is_has: !1
            }), this.getData();
        },
        hide: function() {},
        resize: function() {}
    },
    lifetimes: {
        ready: function() {
            this.getData(), this.get_buy_data(), this._getBalancePwdInfo();
        }
    },
    data: {
        count: "",
        subscribe_title: "",
        activity_id: "",
        datas: {},
        list: [ {
            label: "全部",
            status: null
        }, {
            label: "未开始",
            status: 0
        }, {
            label: "进行中",
            status: 1
        }, {
            label: "已成功",
            status: 2
        }, {
            label: "已失败",
            status: 44
        } ],
        current_index: 0,
        listData: [],
        sex: [ "会员", "管理员" ],
        type: [ "登录密码", "支付密码" ],
        index: 0,
        pay_index: 0,
        role: "member",
        is_admin: !1,
        require_pwd: !1,
        show_pay: !1,
        show_dialog: !1,
        password_open: !0,
        password: "",
        active_value: 0,
        current_page: 1,
        last_page: 1,
        status: null,
        password_show: !1,
        is_has: !1
    },
    methods: {
        _getBalancePwdInfo: function() {
            var a = this, s = t.getNetAddresss("member.balance-password.is-has-password");
            t._getNetWork({
                url: s,
                success: function(t) {
                    var s = t.data;
                    1 == s.result ? a.setData({
                        is_has: s.data.is_has
                    }) : console.log(s.msg);
                },
                fail: function(t) {
                    console.log(t.msg);
                }
            });
        },
        handleInput: function(t) {
            this.setData({
                count: t.detail.value
            });
        },
        closeDialog: function() {
            this.setData({
                show_dialog: !1
            });
        },
        sigin_handle: function(a) {
            var s = this, e = {
                stage_id: this.data.activity_id,
                amount: this.data.count,
                admin: this.data.index
            };
            0 == this.data.index && 1 == this.data.require_pwd && (e.pwd_type = 0 == this.data.pay_index ? "login" : "pay", 
            e.pwd = this.data.password), t._getNetWork({
                url: t.getNetAddresss("plugin.sign-buy.frontend.user-sign.submit"),
                data: e,
                success: function(a) {
                    var e = a.data, i = e.result, n = e.msg, r = e.data;
                    0 != i ? (t.tips(n), s.getData(), s.get_buy_data(), s.setData({
                        show_dialog: !1,
                        index: 0,
                        amount: "",
                        password: "",
                        show_pay: !1
                    })) : 0 == s.data.index && 1 == s.data.require_pwd && 1 == s.data.pay_index && 1 == r.password_error ? s.setData({
                        password_show: !0
                    }) : t.tips(n);
                }
            });
        },
        onClickHide: function() {
            this.setData({
                password_show: !1
            });
        },
        password_handle: function(t) {
            "forget" == t.currentTarget.dataset.type ? this.data.is_has ? wx.navigateTo({
                url: "/packageA/member/balance_password/balance_password"
            }) : wx.navigateTo({
                url: "/packageA/member/set_balance_password/set_balance_password"
            }) : this.setData({
                password_show: !1
            });
        },
        finish: function() {
            this.getData();
        },
        confirm: function(a) {
            var s = a.currentTarget.dataset.type;
            if ("subscribe" == s) {
                if (this.data.count <= 0) return t.tips("请输入有效签到认购数量");
                this.data.is_admin || "0" == this.data.require_pwd ? this.sigin_handle("subscribe") : this.data.password_open && this.setData({
                    show_pay: !0
                });
            }
            if ("pay" == s) {
                if ("" == this.data.password) return t.tips("请输入".concat(0 == this.data.pay_index ? "登录" : "支付", "密码"));
                this.sigin_handle("pay");
            }
        },
        handle_password: function(t) {
            this.setData({
                password: t.detail.value
            });
        },
        closePay: function() {
            this.setData({
                show_pay: !1
            });
        },
        choose: function(t) {
            var a = t.currentTarget.dataset, s = a.i;
            "member" == a.type ? this.setData({
                index: s,
                role: 1 == s ? "admin" : "member"
            }) : this.setData({
                pay_index: s
            });
        },
        sign_list_data: function(a) {
            var s = this;
            t._getNetWork({
                url: t.getNetAddresss("plugin.sign-buy.frontend.sign-buy-page.activity-list"),
                data: a,
                success: function(a) {
                    var e = a.data, i = e.result, n = e.data, r = e.msg;
                    if (0 == i) return t.tips(r);
                    s.setData({
                        listData: n.data
                    }), s.triggerEvent("more_data_page", {
                        current_page: n.current_page,
                        last_page: n.last_page,
                        status: s.data.status
                    });
                }
            });
        },
        get_buy_data: function() {
            var a = this;
            t._getNetWork({
                url: t.getNetAddresss("plugin.sign-buy.frontend.user-sign.index"),
                success: function(t) {
                    var s = t.data, e = s.result, i = s.msg, n = s.data, r = n.active_value, d = n.is_admin, o = n.require_pwd;
                    if (0 == e) return a.$toast(i);
                    a.setData({
                        active_value: r,
                        require_pwd: o,
                        is_admin: d
                    });
                }
            });
        },
        getData: function() {
            var a = this;
            this.sign_list_data(), t._getNetWork({
                url: t.getNetAddresss("plugin.sign-buy.frontend.sign-buy-page.home"),
                success: function(s) {
                    var e = s.data, i = e.data, n = e.result, r = e.msg;
                    if (console.log(i), 0 == n) return t.tips(r);
                    var d = i.carousel_h5_link, o = i.banner_h5_link, u = i.banner_thumb_url, _ = i.carousel_imgs_url, l = i.sign_multiple, c = i.activity_list;
                    a.setData({
                        carousel_h5_link: d,
                        banner_h5_link: o,
                        banner_thumb_url: u,
                        carousel_imgs_url: _,
                        sign_multiple: l,
                        activity_list: c
                    });
                }
            });
        },
        sign_subscribe_handle: function(t) {
            var a = t.detail.item;
            this.setData({
                datas: a,
                show_dialog: !0,
                subscribe_title: a.activity_name,
                activity_id: a.stage_id,
                count: "",
                password: ""
            });
        },
        handle: function(t) {
            var a = t.currentTarget.dataset.status, s = {}, e = t.currentTarget.dataset.index;
            this.setData({
                current_index: e,
                status: a
            }), null !== a && (s.status = a), this.sign_list_data(s);
        }
    }
});